﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DM_TOOLS.Tools.DBC.HEX
{
    public static class DecimalConversion
    {
        /// <summary>
        /// 把 "0x151" / "151" / "FF" 这样的16进制字符串转成10进制整数
        /// </summary>
        public static int HexToDecimal(this string hexStr)
        {
            if (string.IsNullOrWhiteSpace(hexStr))
                throw new ArgumentException("输入不能为空");

            hexStr = hexStr.Trim();

            if (hexStr.StartsWith("0x", StringComparison.OrdinalIgnoreCase))
                hexStr = hexStr.Substring(2);

            return Convert.ToInt32(hexStr, 16);
        }
    }
}
